package com.jsnkj.basic.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.jsnkj.basic.R;
import com.jsnkj.basic.util.ScreenUtils;


public class LoadingDialog extends Dialog {
    private String title;
    private boolean isShowing;

    public LoadingDialog(@NonNull Context context, String title) {
        super(context, R.style.loginlib_loading_dialog);
        this.title = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View inflate = View.inflate(getContext(), R.layout.loginlib_dialog_loading, null);
        setContentView(inflate);
        TextView tvMsg = inflate.findViewById(R.id.tv_message);
        if (title != null) {
            tvMsg.setText(title);
            tvMsg.setVisibility(View.VISIBLE);
        }
        setCancelable(false);

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = ScreenUtils.dp2px(getContext(), 130f);
        lp.height = ScreenUtils.dp2px(getContext(), 130f);
        getWindow().setAttributes(lp);
    }

    public void showLoading() {
        if (!this.isShowing) {
            this.show();
        }
    }

    public void hideLoading() {
        if (this.isShowing()) {
            this.dismiss();
        }
    }

}
